commit: Add --canonical-permissions argument
authorAlexander Larsson <alexl@redhat.com>
Sun, 26 Mar 2017 09:01:25 +0000 (11:01 +0200)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 27 Mar 2017 13:48:41 +0000 (13:48 +0000)
This adds to file permission masks the same bitmask that will
be applied to file objects in bare-user* repos. This will be
needed in the testsuite to ensure that the things we commit
will be expressable in bare-user-only repos.

Closes: #750
Approved by: cgwalters

src/libostree/ostree-repo-commit.c
src/libostree/ostree-repo.h
src/ostree/ot-builtin-commit.c

index 80c35f4493f604971e41bd1f2b19fab9a0d5b9af..0e85bcb16be988d4c67d4d2bd93f8666843ddcbb 100644 (file)
@@ -2236,17 +2236,33 @@ _ostree_repo_commit_modifier_apply (OstreeRepo               *self,
                                     GFileInfo                *file_info,
                                     GFileInfo               **out_modified_info)
 {
-  OstreeRepoCommitFilterResult result;
+  OstreeRepoCommitFilterResult result = OSTREE_REPO_COMMIT_FILTER_ALLOW;
   GFileInfo *modified_info;
 
-  if (modifier == NULL || modifier->filter == NULL)
+  if (modifier == NULL ||
+      (modifier->filter == NULL &&
+       (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS) == 0))
     {
       *out_modified_info = g_object_ref (file_info);
       return OSTREE_REPO_COMMIT_FILTER_ALLOW;
     }
 
   modified_info = g_file_info_dup (file_info);
-  result = modifier->filter (self, path, modified_info, modifier->user_data);
+  if (modifier->filter)
+    result = modifier->filter (self, path, modified_info, modifier->user_data);
+
+  if ((modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS) != 0)
+    {
+
+      if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR)
+        {
+          guint current_mode = g_file_info_get_attribute_uint32 (modified_info, "unix::mode");
+          g_file_info_set_attribute_uint32 (modified_info, "unix::mode", current_mode | 0744);
+        }
+      g_file_info_set_attribute_uint32 (modified_info, "unix::uid", 0);
+      g_file_info_set_attribute_uint32 (modified_info, "unix::gid", 0);
+    }
+
   *out_modified_info = modified_info;
 
   return result;
@@ -2283,7 +2299,9 @@ apply_commit_filter (OstreeRepo               *self,
                      GFileInfo                *file_info,
                      GFileInfo               **out_modified_info)
 {
-  if (modifier == NULL || modifier->filter == NULL)
+  if (modifier == NULL ||
+      (modifier->filter == NULL &&
+       (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS) == 0))
     {
       *out_modified_info = g_object_ref (file_info);
       return OSTREE_REPO_COMMIT_FILTER_ALLOW;
@@ -2312,7 +2330,8 @@ get_modified_xattrs (OstreeRepo                       *self,
       ret_xattrs = modifier->xattr_callback (self, relpath, file_info,
                                              modifier->xattr_user_data);
     }
-  else if (!(modifier && (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS) > 0)
+  else if (!(modifier && (modifier->flags & (OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS |
+                                             OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS)) > 0)
            && !self->disable_xattrs)
     {
       if (path && OSTREE_IS_REPO_FILE (path))
index 34685cc6c259d9a8d4e8d28073ab7040e7f3af08..b88b980fae047b8e1094e9e0fb49ae04f8ceb71d 100644 (file)
@@ -536,11 +536,13 @@ typedef OstreeRepoCommitFilterResult (*OstreeRepoCommitFilter) (OstreeRepo    *r
  * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_NONE: No special flags
  * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS: Do not process extended attributes
  * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES: Generate size information.
+ * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS: Canonicalize permissions for bare-user-only mode.
  */
 typedef enum {
   OSTREE_REPO_COMMIT_MODIFIER_FLAGS_NONE = 0,
   OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS = (1 << 0),
-  OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES = (1 << 1)
+  OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES = (1 << 1),
+  OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS = (1 << 2),
 } OstreeRepoCommitModifierFlags;
 
 /**
index 218fb70182971a9cb4efa2390840e711e2038143..e6738c89c15c9b447e7ef19917619123cc821867 100644 (file)
@@ -45,6 +45,7 @@ static gboolean opt_link_checkout_speedup;
 static gboolean opt_skip_if_unchanged;
 static gboolean opt_tar_autocreate_parents;
 static gboolean opt_no_xattrs;
+static gboolean opt_canonical_permissions;
 static char **opt_trees;
 static gint opt_owner_uid = -1;
 static gint opt_owner_gid = -1;
@@ -84,6 +85,7 @@ static GOptionEntry options[] = {
   { "add-detached-metadata-string", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_detached_metadata_strings, "Add a key/value pair to detached metadata", "KEY=VALUE" },
   { "owner-uid", 0, 0, G_OPTION_ARG_INT, &opt_owner_uid, "Set file ownership user id", "UID" },
   { "owner-gid", 0, 0, G_OPTION_ARG_INT, &opt_owner_gid, "Set file ownership group id", "GID" },
+  { "canonical-permissions", 0, 0, G_OPTION_ARG_NONE, &opt_canonical_permissions, "Canonicalize permissions in the same way bare-user does for hardlinked files", NULL },
   { "no-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_no_xattrs, "Do not import extended attributes", NULL },
   { "link-checkout-speedup", 0, 0, G_OPTION_ARG_NONE, &opt_link_checkout_speedup, "Optimize for commits of trees composed of hardlinks into the repository", NULL },
   { "tar-autocreate-parents", 0, 0, G_OPTION_ARG_NONE, &opt_tar_autocreate_parents, "When loading tar archives, automatically create parent directories as needed", NULL },
@@ -399,6 +401,8 @@ ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError
 
   if (opt_no_xattrs)
     flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS;
+  if (opt_canonical_permissions)
+    flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS;
   if (opt_generate_sizes)
     flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES;
   if (opt_disable_fsync)